/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.skuboard.model.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.skuboard.model.Student;

/**
 *
 * @author clockbuilder
 */
public class SchoolDAOImpl implements SchoolDAO {

    List<Student> studentsDb = new ArrayList<Student>();

    public SchoolDAOImpl() {
        Date dob = new Date();
        Student student1 = new Student("127", "Mawuli", "Obuntu", "Kofi Pomodorro", dob, "20 Aluguntuguntu St.", "mawuli@pomodorroinc.com","Form 3");
        Student student2 = new Student("128", "Maxwell", "Donkor", "Maxdee Kweku", dob, "Box HP429", "prosper@bossinc.com","Form 2");
        Student student3 = new Student("129", "Alexander", "Ojo", "Titiloye ", dob, "PMB 440 Hohoe", "ojo@alex.com","Form 1");
        Student student4 = new Student("130", "Fiifi", "Buckman", "Ebo", dob, "Coast St. Elmina", "bossu@cashmoni.com","Form 2");
        studentsDb.add(student1);
        studentsDb.add(student2);
        studentsDb.add(student3);
        studentsDb.add(student4);
    }

    public void setStudentsDb(List<Student> studentsDb) {
        this.studentsDb = studentsDb;
    }

    @Override
    public boolean removeStudentById(String studentId) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public Student getStudentById(String studentId) {
        Iterator<Student> it = studentsDb.iterator();
        Student foundStudent = null;
        while (it.hasNext()) {
            Student student = it.next();
            if (student.getId().equals(studentId)) {
                return foundStudent = student;
            }
        }
        return foundStudent;
    }

    @Override
    public boolean addStudent(Student newStudent) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Student> getAllStudents() {
        return this.studentsDb;

    }

    @Override
    public String getallStudentsInfo() {
        Iterator<Student> it = studentsDb.iterator();
        String listOfAllStudents = "";
        String NEW_LINE_SEPARATOR = "<br>";
        Student student = null;
        while (it.hasNext()) {
            student = it.next();
            listOfAllStudents = listOfAllStudents + NEW_LINE_SEPARATOR + student.toString();
        }
        return listOfAllStudents;
    }

    @Override
    public String getStudentInfo(String studentId) {
       
                Iterator<Student> it = studentsDb.iterator();
        while (it.hasNext()) {
            Student student = it.next();
            if (student.getId().equals(studentId)) {
                int studentIndex = studentsDb.indexOf(student);
                Student foundStudent = studentsDb.get(studentIndex);
                return foundStudent.toString();
            }
        }
        return "Student with Id#---->" + studentId + " not Found";
    }
}
